﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using PlatformManagement.Properties;
using Platform.Model;

namespace PlatformManagement
{
    public partial class MainForm : RibbonForm
	{
		public MainForm()
		{
			InitializeComponent();
		    this.Text = Resources.MainForm_Title + "-" + Resources.MainForm_Version__ + Devsoft.Utilities.Version.GetVersion();
		}

        #region Toolbar action
        private void BtnMarketClick(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(MarketForm))
                {
                    form.Activate();
                    return;
                }
            }

            var marketForm = new MarketForm() { MdiParent = this };
            marketForm.Show();
        }

        private void BtnStoreClick(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(StoreForm))
                {
                    form.Activate();
                    return;
                }
            }

            var storeForm = new StoreForm() { MdiParent = this };
            storeForm.Show();
        }

        private void BtnSupplierClick(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(SupplierForm))
                {
                    form.Activate();
                    return;
                }
            }

            var supplierForm = new SupplierForm() { MdiParent = this };
            supplierForm.Show();
        }

        private void BtnArticleClick(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(ArticleForm))
                {
                    form.Activate();
                    return;
                }
            }

            var articleForm = new ArticleForm() { MdiParent = this };
            articleForm.Show();
        }

        private void BtnPackageClick(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(PackageForm))
                {
                    form.Activate();
                    return;
                }
            }

            var packageForm = new PackageForm() { MdiParent = this };
            packageForm.Show();
        }

        private void BtnOrderClick(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(DailyOrderForm))
                {
                    form.Activate();
                    return;
                }
            }

            var dailyOrderForm = new DailyOrderForm() { MdiParent = this };
            dailyOrderForm.Show();
        }


        private void btnPicking_Click(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(PickingForm))
                {
                    form.Activate();
                    return;
                }
            }

            var pickingForm = new PickingForm() { MdiParent = this };
            pickingForm.Show();
        }

        #endregion
        
		#region Form's events

		private void MainFormFormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void MainFormLoad(object sender, EventArgs e)
        {
            lblUser.Text = string.Format("{0} : {1}", Resources.MainForm_UserText,
                                         WorkSession.Current.CurrentUser.FullName);
            lblMarket.Text = string.Format("{0} : {1}", Resources.LoginForm_MarketText,
                                           WorkSession.Current.Market.MarketName);
            this.Text = string.Format("{0} - {1}", WorkSession.Current.Market.MarketName, "Platform");
        }

		#endregion Form's events

		#region System menu

		private void BtnExitClick(object sender, EventArgs e)
		{
			Application.Exit();
		}

		#endregion System menu
        /// <summary>
        /// Xử lí Button Logout
        /// Khi Logout khỏi hệ thống, sẽ trả về lại Form Login
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogout_Click(object sender, EventArgs e)
        {
            MainForm.ActiveForm.Hide();
            var loginform = new LoginForm();
            loginform.Show();
        }

        private void btnLackReport_Click(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(LackReportForm))
                {
                    form.Activate();
                    return;
                }
            }

            var lackReporForm = new LackReportForm() { MdiParent = this };
            lackReporForm.Show();
        }

        private void btnUserManager_Click(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(EmployeeForm))
                {
                    form.Activate();
                    return;
                }
            }

            var employeeform = new EmployeeForm() { MdiParent = this };
            employeeform.Show();
        }

        private void btnBackup_Click(object sender, EventArgs e)
        {
            BackupForm frm= new BackupForm();
            frm.ShowDialog();
        }

        private void btnRestore_Click(object sender, EventArgs e)
        {
            RestoreForm frm= new RestoreForm();
            frm.ShowDialog();
        }

        private void btnStockIn_Click(object sender, EventArgs e)
        {
           
        }

        private void btnStockReport_Click(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(StockReportForm))
                {
                    form.Activate();
                    return;
                }
            }

            var StockReportForm = new StockReportForm() { MdiParent = this };
            StockReportForm.Show();
        }

        private void btnKPIReport_Click(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.GetType() == typeof(KpiReportForm))
                {
                    form.Activate();
                    return;
                }
            }

            var KpiReportForm = new KpiReportForm() { MdiParent = this };
            KpiReportForm.Show();
        }

        
	}
}
